import { jsonp } from '@/common/js/getData';
import { commonParams, options, ERR_OK } from '@/common/js/config';
import axios from 'axios';
import api from './apiUrl';

export function getSliderList() {
  const url = api.recommendSliderList;
  const data = Object.assign({}, commonParams, {
    platform: 'h5',
    uin: 0,
    needNewCode: 1,
  });
  return jsonp(url, data, options).then((res) => {
    // jsonp res
    if (res.code === ERR_OK) {
      return Promise.resolve(res.data);
    }
    return 'error';
  }).catch(err => console.error(err));
}

export function getDiscList() {
  const url = api.discList;
  const data = Object.assign({}, commonParams, {
    platform: 'yqq',
    hostUin: 0,
    sin: 0,
    ein: 29,
    sortId: 5,
    needNewCode: 0,
    categoryId: 10000000,
    rnd: Math.random(),
    format: 'json',
  });
  return axios.get(url, {
    params: data,
  }).then((res) => {
    // express res
    if (res.data.code === ERR_OK) {
      return Promise.resolve(res.data.data);
    }
    return 'error';
  }).catch(err => console.error(err));
}

export function getSongList(disstid) {
  const url = api.songList;
  const data = Object.assign({}, commonParams, {
    disstid,
    type: 1,
    json: 1,
    utf8: 1,
    onlysong: 0,
    platform: 'yqq',
    hostUin: 0,
    needNewCode: 0,
    format: 'json',
  });
  return axios.get(url, {
    params: data,
  }).then((res) => {
    return Promise.resolve(res.data);
  });
  // const url = api.songList;
  // const data = Object.assign({}, commonParams, {
  //   disstid,
  //   type: 1,
  //   json: 1,
  //   utf8: 1,
  //   onlysong: 0,
  //   platform: 'yqq',
  //   hostUin: 0,
  //   needNewCode: 0,
  //   g_tk: 67232076,
  // });
  // return jsonp(url, data, options).then((res) => {
  //   console.log(res);
  //   // jsonp res
  //   if (res.code === ERR_OK) {
  //     return Promise.resolve(res.data);
  //   }
  //   return 'error';
  // }).catch(err => console.error(err));
}
